/*************************************************************************
> File Name: fool_sort.c
> Author: icebear
> Mail: 3322366195@qq.com
> Created Time: 2023-07-22 09:13:36
> Description: 原始的笨蛋排序---负优化的冒泡排序
************************************************************************/

#include <stdio.h>
#include "general.h"

void foolSort(int arr[], int length);

int main(int argc, char const *argv[])
{
    int arr[] = {9, 4, 2, 7, 5, 1, 8, 3, 6, 0};
    int size = sizeof(arr) / sizeof(arr[0]);
    printf("Original array: \n");
    printArr(arr, size);
    foolSort(arr, size);
    printf("Sorted array: \n");
    printArr(arr, size);
    return 0;
}

void foolSort(int arr[], int length)
{
    int i = 0, j = 0;
    for (i = 0; i < length; i++)
    {
        for (j = 1; j < length; j++)
        {
            if (arr[j - 1] > arr[j])
            {
                swap(&arr[j - 1], &arr[j]);
            }
        }
    }
}